package day07;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 读取当前项目根目录下所有后缀为.obj的文件，将这些Emp对象读取出来
 * 并存入到一个List集合中，然后按照员工工资从多到少的顺序依次输出员工信息
 * @author Bonnie
 *
 */
public class Test04 {
    public static void main(String[] args) throws IOException {
        ArrayList<Emp> emps = new ArrayList<>();
        BufferedReader[] brs;
        File file = new File("./");
        File[] files = file.listFiles();
        for (File f:files){
            if(f.getName().endsWith(".obj")&&f.isFile()){
                BufferedReader br = new BufferedReader(new FileReader(f));
                String str = br.readLine();
                String[] strs = str.split(",");
                String name = strs[0];
                int age = Integer.parseInt(strs[1]);
                String gender = strs[2];
                int salary = Integer.parseInt(strs[3]);
                String date = strs[4];
                emps.add(new Emp(name,age,gender,salary,date));
            }
        }

        emps.sort(Comparator.comparingInt(Emp::getSalary));
        for (Emp e:emps){
            System.out.println((e.toString()));
        }
//        List<Path> objFiles = Files.walk(Paths.get("./"))
//                .filter(path -> path.getFileName().toString().endsWith(".obj"))
//                .collect(Collectors.toList());

    }
}
